<template>
	<view v-if="pageShow">
		<view class="flexbetween mainpadding ffffff" @click="jumpurl('/pages_mypage/dizhi?type=1')">
			<view class="" v-if="dataAll.addressData">
				<view class="flexleft">
					<view class="xiaolv sanshier nofonweight" v-if="dataAll.addressData.status==1">【默认】</view>
					<view class="xiaohei sanshier nofonweight margin_right2">{{dataAll.addressData.name}}</view>
					<view class="xiaohui ershiba nofonweight">{{dataAll.addressData.mobile}}</view>
				</view>
				<view class="xiaohei ershiba nofonweight margin_top2">{{dataAll.addressData.cityinfo}}{{dataAll.addressData.address_detail}}</view>
			</view>
			<view class="xiaohei sanshier nofonweight" v-else>
				点击选择收货地址
			</view>
			<u-icon name="arrow-right"></u-icon>
		</view>
		<view class="mainpadding ffffff margin_top1" v-for="item in orderData.lists" :key="item.id">
			<view class="flextop">
				<view class="shilitu">
					<image :src="item.products.image_text" mode=""></image>
				</view>
				<view class="" style="width: 69%;">
					<view class="sanshier xiaohei fonweight yhxk">{{item.products.name}}</view>
					<view class="flexbetween margin_top6">
						<view class="flexleft">
							<view class="sanshier xiaohong fonweight">{{item.products.score}}</view>
							<view class="strongtext xiaohong nofonweight">积分</view>
							<view class="sanshier xiaohong fonweight" v-if="Number(item.products.price)">+{{item.products.price}}元</view>
						</view>
						<view class="strongtext xiaohui nofonweight">x{{item.number}}</view>
					</view>
				</view>
			</view>
		</view>
		<view class="ffffff mainpadding margin_top1">
			<view class="sanshier fonweight xiaohei">订单金额</view>
			<view class="xiahuaxian flexbetween margin_top">
				<view class="ershiba nofonweight xiaohei">订单金额：</view>
				<view class="ershiba nofonweight xiaohei">￥{{orderData.statis.allsub_price}}元</view>
			</view>
			<view class="xiahuaxian flexbetween margin_top">
				<view class="ershiba nofonweight xiaohei">积分：</view>
				<view class="ershiba nofonweight xiaohei">{{orderData.statis.allsub_score}}积分</view>
			</view>
			<view class=" flexbetween margin_top">
				<view class="ershiba nofonweight xiaohei">订单备注：</view>
				<input class="textright" type="text" placeholder="选填" v-model="remarks">
			</view>
		</view>
		<!-- 固定底部 -->
		<view class="gudingdb mainpadding ffffff flexbetween">
			<view class="strongtext xiaohei nofonweight flexleft">需支付：
				<view class="flexleft">
					<view class="sanshier xiaohong fonweight">{{orderData.statis.allsub_score}}</view>
					<view class="strongtext xiaohong nofonweight">积分</view>
					<view class="sanshier xiaohong fonweight" v-if="Number(orderData.statis.allsub_price)">+{{orderData.statis.allsub_price}}元</view>
				</view>
			</view>
			<view class="xiaobtnty" @click="tzyyxx">提交订单</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				type:"",
				address_id:"",//detail=商品详情,cart=购物车
				remarks:"",
				data:[],
				dataAll:{},
				orderData:{},
				pageShow:false
			}
		},
		onLoad(options) {
			let data = JSON.parse(decodeURIComponent(options.msg))
			this.type = data.type
			this.data = data.data
		},
		onShow() {
			uni.$off("checkaddress")
			uni.$on("checkaddress",data=>{
				this.address_id = data
			})
			this.init()
		},
		methods: {
			jumpurl(url){
				uni.navigateTo({
					url
				})
			},
			init(){
				httpRequest.request('/api/Scoregoods/getOrderGoodsList', 'POST', {
					address_id:this.address_id,
					data:this.data,
					type:this.type,
				}, false, false, true).then(res => {
					if(res.data.addressData){
						this.address_id = res.data.addressData.id
					}
					this.dataAll = res.data
					this.orderData = res.data.orderData
					this.pageShow = true
				})
			},
			// 跳转支付
			tzyyxx() {
				httpRequest.request('/api/scoregoods/addOrder', 'POST', {
					address_id:this.address_id,
					data:this.data,
					pay_type:0,
					type:this.type,
					remarks:this.remarks
				}, false, false, true).then(res => {
					if(res.code==1){
						uni.redirectTo({
							url: '/pages_mypage/zhifu?id='+res.data.id+"&price="+res.data.pay_price+"&total_score="+res.data.pay_score
						})
					}else{
						httpRequest.toast(res.msg)
					}
				})
				
			},
		}
	}
</script>

<style lang="scss" scoped>
	.shilitu {
		width: 200rpx;
		height: 160rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}

	page {
		background: #F9F9F9;
	}
</style>